<!DOCTYPE html>
<html>

<head>

    <style>
        body {
            background-color: #f2f2f2;
        }

        .container {
            border: 2px solid #ccc;
            border-radius: 10px;
            margin-top: 50px;
            margin-left: 100px;
            width: 400px;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0px 0px 10px #ccc;
        }

        h1 {
            text-align: center;
        }

        input[type=text],
        input[type=password] {
            width: 100%;
            padding: 12px 20px;
            margin: 20px 0;
            /* display: inline-block; */
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        button {
            background-color: skyblue;
            color: white;
            padding: 14px 20px;
            margin: 8px 0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }

        button:hover {
            background-color: #45a049;
        }
    </style>
</head>

<body>
    <container>
        <div class="container">
            <input type="text" class="user" placeholder="请输入账号">
            <input type="text" class="pwd" placeholder="请输入密码">
            <button class="btn">登录</button>
        </div>
    </container>
</body>

<script src="./a.js"></script>

<script>
    $$('.btn').onclick = function () {
        const user = $$('.user').value;
        const pwd = $$('.pwd').value;

        ajax({
            type: 'post',
            url: 'http://121.43.116.41/php/login.php',
            data: {
                username: user,
                password: pwd
            },
            success: res => {
                console.log(res);
                const { msg, status } = res;
                if (status) {
                    //登录成功，跳转到首页
                    // location.href = 'index.html'
                    //登录到首页需要记住登录的用户名，需要跨页面访问数据
                    //所以使用cookie将用户名存起来
                    setCookie('magic', user)
                } else {
                    //登录失败，给出提示
                    alert(msg)
                }
            }
        })
    }
</script>



</html>